import random
from time import sleep
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get("https://ebank.xacbank.com/XAEIBankDemo/page/login/login.html?t=1679974008665")
sleep(3)
#输入密码
#<input id="account" type="password" class="form-control form-input" placeholder="请输入密码">
driver.find_element(By.ID,"account").send_keys("123456")
sleep(1)
#点击提交
#<button id="login" type="button" class="btn" style="width:395px;display:block;">演示版登录</button>
driver.find_element(By.ID,"login").click()
sleep(3)
#点击叉号关闭弹窗
#<a id="fw-gen-10009-closable" optid="close" class="close icon icon-close" data-dismiss="modal"></a>
#<a id="fw-gen-10009-closable" optid="close" class="close icon icon-close" data-dismiss="modal"></a>
driver.find_element(By.ID,"fw-gen-10009-closable").click()
sleep(2)
#找到侧边栏转账汇款按钮点击
#//*[@id="1"]/div/div/span[2]
#<li class="item" _index="1" id="1"><div class="item_bg"><div class="title"><span class="title_icon icon-menu2"></span><span>转账汇款</span></div></div></li>
driver.find_element(By.XPATH,'//*[@id="1"]/div/div/span[2]').click()
sleep(1)
#鼠标移动到行内转账点击
#//*[@id="fw-gen-10005-body"]/ul[2]/li
#//*[@id="fw-gen-10005-body"]/ul[2]/li/a
driver.find_element(By.XPATH,'//*[@id="fw-gen-10005-body"]/ul[2]/li/a').click()
sleep(5)
#
#<iframe id="fw-gen-10007-body" class="body" src="https://ebank.xacbank.com/XAEIBankDemo/page/02/0202/020201.html" width="100%" frameborder="no" <!--="" scrolling="auto" --="" style="height: 767.667px;">></iframe>
#<select class="form-control" type="text" id="payAccount" style="font-size:14px;"><option value="781011510000007032" acctype="01" accname="企业网银演示版公司">781011 51000 0007032/基本户</option><option value="781011600000001297" acctype="02" accname="企业网银演示版公司">781011 60000 0001297</option><option value="781011590000001040" acctype="03" accname="企业网银演示版公司">781011 59000 0001040/收费</option><option value="781011570000003224" acctype="04" accname="企业网银演示版公司">781011 57000 0003224/开户代发</option></select>
#切换至1007
a = driver.find_element(By.ID, "fw-gen-10007-body")
driver.switch_to.frame(a)
#选择任意账户转账
from faker import Faker
faker = Faker()
n = random.choice([1, 2, 3, 4])
##payAccount > option:nth-child(1)
##payAccount > option:nth-child(2)
#//*[@id="payAccount"]/option[2]
driver.find_element(By.XPATH, f'//*[@id="payAccount"]/option[{n}]').click()
sleep(5)
#选择收款户名
#<span class="icon_find" id="find-person" style="top:14px">
driver.find_element(By.ID, "find-person").click()
sleep(1)
#跳转至新的<iframe
driver.switch_to.default_content()
#//*[@id="fw-gen-10011-iframe"]
#<iframe id="fw-gen-10011-iframe" class="iframe-body" frameborder="no" scrolling="auto" style="height: 420px; width: 800px; display: inline;" src="https://ebank.xacbank.com/XAEIBankDemo/page/acc/finduserlocal.html?title=020201|转账汇款 / 行内转账"></iframe>
b = driver.find_element(By.ID,'fw-gen-10011-iframe')
driver.switch_to.frame(b)
sleep(2)
n = random.choice([1,2,3])
#点击选择
#//*[@id="fw-gen-10001-tbody"]/tr[1]/td[1]/label
#//*[@id="fw-gen-10001-tbody"]/tr[2]/td[1]/label
#//*[@id="fw-gen-10001-tbody"]/tr[3]/td[1]/label
driver.find_element(By.XPATH,f'//*[@id="fw-gen-10001-tbody"]/tr[{n}]/td[1]/label').click()
# //*[@id="fw-gen-10001-tbody"]/tr[1]/td[1]/label
# <input class="checkBoxClass" type="checkbox" name="cbox" id="cbox0" onclick="App.chooseThis(this);">
sleep(1)
#退出<iframe
driver.switch_to.default_content()
sleep(1)
#点击确定
#<div id="fw-gen-10011-footer" class="modal-footer"><button optid="" type="button" class="btn btn-second" style="" data-dismiss="modal">取消</button><button optid="" type="button" class="btn btn-primary" style="" data-dismiss="modal">确定</button></div>
#//*[@id="fw-gen-10011-footer"]/button[2]
driver.find_element(By.XPATH,'//*[@id="fw-gen-10011-footer"]/button[2]').click()
sleep(1)
#退出10011footer进入10007
driver.switch_to.default_content()
a = driver.find_element(By.ID, "fw-gen-10007-body")
driver.switch_to.frame(a)
#<input type="text" style="width:276px;border-left-width:0px;margin-left:-4px;outline:none;" class="money" id="money" placeholder="请输入金额" onkeyup="App.moneyUpper(this.value)" maxlength="16">
sleep(3)
# #<input class="checkBoxClass" type="checkbox" name="cbox" id="cbox0" onclick="App.chooseThis(this);">
# #//*[@id="fw-gen-10001-tbody"]/tr[1]/td[1]/label
# #//*[@id="cbox0"]
# #//*[@id="fw-gen-10001-tbody"]/tr[1]/td[1]/label
# #<tr class="item" _index="1" _page="1"><td><input class="checkBoxClass" type="checkbox" name="cbox" id="cbox1" onclick="App.chooseThis(this);"><label for="cbox1" class="checkBoxLabelClass checkedLabel"><span class="spanSelected">&nbsp;</span></label></td><td>赵云</td><td id="" name="">622136 50101 0364433</td><td>西安银行</td><td>默认分组</td></tr>
# baike = driver.find_element(By.XPATH,'input#cbox1')
# ac = ActionChains(driver)
# ac.move_to_element(baike).click().perform()
#
# sleep(5)
# """
# selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression
#
# """
# #选择一个收款人作为户名
# #<input class="checkBoxClass" type="checkbox" name="cbox" id="cbox0" onclick="App.chooseThis(this);">
# #<input class="checkBoxClass" type="checkbox" name="cbox" id="cbox1" onclick="App.chooseThis(this);">
# #<input class="checkBoxClass" type="checkbox" name="cbox" id="cbox2" onclick="App.chooseThis(this);">
# #<label for="cbox0" class="checkBoxLabelClass"><span class="spanSelected">&nbsp;</span></label>
# n = random.choice([0,1,2])
# driver.find_element(By.XPATH, f'//*[@id="fw-gen-10001-tbody"]/tr[{n}]').click()
# sleep(5)
#输入转账金额
#<input type="text" style="width:276px;border-left-width:0px;margin-left:-4px;outline:none;" class="money" id="money" placeholder="请输入金额" onkeyup="App.moneyUpper(this.value)" maxlength="16">
driver.find_element(By.ID,"money").send_keys("1000")
sleep(1)
#选择用途
#//*[@id="useFor"]
driver.find_element(By.XPATH,'//*[@id="useFor"]').click()
sleep(1)
# #//*[@id="payUse"]
# driver.find_element(By.XPATH,'//*[@id="payUse"]').click()
# sleep(1)
#//*[@id="payUse"]/ul/li[1]
#//*[@id="payUse"]/ul/li[1]
#//*[@id="payUse"]/ul/li[11]
#//*[@id="payUse"]
#//*[@id="payUse"]/ul
#//*[@id="payUse"]/ul/li[1]/div/div[1]
#//*[@id="payUse"]/ul/li[2]/div/div
#//*[@id="payUse"]/ul/li[3]/div/div
#//*[@id="payUse"]/ul/li[10]/div/div
#//*[@id="payUse"]/ul/li[7]/div/div
n = random.choice([1,2,3,4,5,6,7,8,9,10,11])
driver.find_element(By.XPATH,f'//*[@id="payUse"]/ul/li[{n}]/div/div').click()
sleep(1)
#提交确认
#<button type="button" id="next_btn" class="btn btn-primary" style="display: inline-block;">下一步</button>
driver.find_element(By.ID,"next_btn").click()
sleep(3)